home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / internet / vbipsmtp / smtp.bas < prev    next >
Encoding:
BASIC Source File  |  1996-02-17  |  3.2 KB  |  109 lines

  1. Attribute VB_Name = "smtp"
  2. Option Explicit
  3. '---------------------------------------------------
  4. 'SMTP.BAS
  5. 'Copyright 1996 by Carl Franklin
  6. 'Unauthorized reproduction in any medium of this
  7. 'source code is strictly prohibited without written
  8. 'permission from the author and John Wiley & Sons.
  9. '---------------------------------------------------
  10. '-- CRLF
  11. Global vbCRLF       As String
  12.     
  13. '-- Holds the last command issued
  14. Global gszCommand   As String
  15.  
  16. '-- These variables hold fields of the
  17. '   messgae to be sent.
  18. Global gszTo        As String
  19. Global gszFrom      As String
  20. Global gszSubject   As String
  21. Global gszMsg       As String
  22. Global gszAttachedFiles()   As String
  23. Global gnNumAttachedFiles   As Integer
  24.  
  25. Global Const gszAttachFile = "ATTACH.BIN"
  26. Function nSendFileAsMsg(szFileName As String, DSSocket As Control, lBlockSize As Long, szFrom As String, szTo As String, szSubject As String, szText As String)
  27. '***********************************************************
  28. '   nSendFileAsMsg (by Carl Franklin)
  29. '
  30. '   This function sends a file via email.
  31. '   If you want to send binary files you must
  32. '   first UUEncode them. Use the function
  33. '   nMakeMsgWithFiles (in UUCODE.BAS) to create
  34. '   a file that has a text message and one or
  35. '   more binary files embedded in it.
  36. '
  37. '   Parameters: szFileName  Full path and filename
  38. '               DSSocket    Sockets control
  39. '               lBlockSize  The maximum size of each block
  40. '                           (default is 8192)
  41. '               szFrom      Sender's email address
  42. '               szTo        Recipient's email address
  43. '               szSubject   Subject of the message
  44. '               szText      Any text you want to tag on
  45. '                           to the top of the message.
  46. '***********************************************************
  47.     
  48.     Dim nMsgFile    As Integer
  49.     Dim szLine      As String
  50.     Dim szBuffer    As String
  51.     
  52.     On Error GoTo nSendFileAsMsg_Error
  53.  
  54.     '-- Default block size = 8K
  55.     If lBlockSize = 0 Then
  56.         lBlockSize = 8192
  57.     End If
  58.     
  59.     '-- Open the message file
  60.     nMsgFile = FreeFile
  61.     Open szFileName For Binary As nMsgFile
  62.    
  63.     '-- szBuffer holds up to <blocksize> number of bytes
  64.     '   and is sent when it becomes full.
  65.     
  66.     '-- Send the header first
  67.     szBuffer = "DATE: " & Format$(Now, "dd mmm yy ttttt") & vbCRLF _
  68.         & "FROM: " & szFrom & vbCRLF _
  69.         & "TO: " & szTo & vbCRLF _
  70.         & "SUBJECT: " & szSubject & vbCRLF & vbCRLF _
  71.         & szText & vbCRLF
  72.     SendData DSSocket, szBuffer
  73.     
  74.     '-- Send the file in chunks
  75.     Do Until EOF(nMsgFile)
  76.         szBuffer = Space$(lBlockSize)
  77.         Get #nMsgFile, , szBuffer
  78.         SendData DSSocket, szBuffer
  79.     Loop
  80.     
  81.     Close nMsgFile
  82.     
  83.     '-- Send the final period.
  84.     SendData DSSocket, vbCRLF & "." & vbCRLF
  85.     
  86.     Exit Function
  87.     
  88. nSendFileAsMsg_Error:
  89.     
  90.     nSendFileAsMsg = Err
  91.     On Error Resume Next
  92.     Close nMsgFile
  93.     Exit Function
  94.  
  95. End Function
  96.  
  97.  
  98. Sub SendSMTPCommand(DSSock As Control, szCmd As String)
  99.  
  100.     '-- Save the last command sent
  101.     gszCommand = szParseString(szCmd, " ", 1)
  102.     
  103.     '-- Send the command
  104.     SendData DSSock, szCmd & vbCRLF
  105.     
  106. End Sub
  107.  
  108.  
  109.